﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;

namespace DevLav
{

    public partial class FormRecords : Form
    {
        List<Record> records = new List<Record>();
        
        public FormRecords()
        {
            InitializeComponent();
            /*for (int i = 0; i < 10; i++)
                records.Add(new Record("Anonim" + i, 0, 0));
            BinaryFormatter bf = new BinaryFormatter();
            using (Stream stream = new FileStream("records.bin", FileMode.Create, FileAccess.Write, FileShare.None))
            {
                bf.Serialize(stream, records);
            }*/

            BinaryFormatter bf = new BinaryFormatter();
            using (Stream stream = new FileStream("records.bin", FileMode.Open, FileAccess.Read, FileShare.None))
            {
                records = (List<Record>)bf.Deserialize(stream);
            }
            WriteRecords();
        }

        private void WriteRecords()
        {
            for (int i = 0; i < 10; i++)
            {
                listView.Items.Add(records[i].Name);
                listView.Items[i].SubItems.Add(records[i].Steps.ToString());
                listView.Items[i].SubItems.Add(records[i].Time.ToString());
            }
        }
    }
}
